<%--
  作者:张伟

  联系:adamzzww@163.com
  时间:2016-11-27
  说明:新增用户信息
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增用户信息</title>
    <%@include file="../../desktop/include/assets.jsp" %>
    <%
        String url = request.getContextPath() + Global.PATH;
    %>

    <style>
        .infoForm {
            padding: 20px
        }
    </style>
</head>
<body>
<div class="infoForm">
    <form id="editForm" name="editForm" class="form-horizontal form-condensed" role="form" method="post"
          action="<%=url%>/user">
        <div class="form-group">
            <label class="col-xs-3 control-label required" for="loginName">登录名</label>
            <div class="col-xs-6">
                <input type="text" name="loginName" id="loginName" value="${userEntity.loginName}" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label" for="userName">真实姓名</label>
            <div class="col-xs-6">
                <input type="text" name="userName" id="userName" value="${userEntity.userName}" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">用户电话</label>
            <div class="col-xs-6">
                <input type="text" name="userPhone" id="userPhone" value="${userEntity.userPhone}" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">用户部门</label>
            <div class="col-xs-6">
                <select name="dept.deptId" id="deptId" class="form-control">
                    <c:if test="${!empty deptList }">
                        <c:forEach items="${deptList }" var="dept">
                            <option value="${dept.deptId}" ${userEntity.dept.deptId == dept.deptId ?"selected":""} >${dept.deptName}</option>
                        </c:forEach>
                    </c:if>

                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">用户角色</label>
            <div class="col-xs-6">
                <select name="role.roleId" id="roleId" class="form-control">
                    <c:if test="${!empty roleList }">
                        <c:forEach items="${roleList }" var="role">
                            <option value="${role.roleId}" ${userEntity.role.roleId == role.roleId ?"selected":""} >${role.roleName}</option>
                        </c:forEach>
                    </c:if>

                </select>
            </div>
        </div>

        <hr/>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" id="saveBtn" class="btn btn-primary" value="保存" data-loading="稍候...">
                <%--<c:if test="${!empty userEntity.userId }">--%>
                <%--<input type="hidden" name="userId" value="${userEntity.userId}">--%>
                <%--</c:if>--%>
            </div>
        </div>
    </form>
</div>

<script>

    $(function () {
        var validate = $("#editForm").validate({
            //debug: true, //调试模式取消submit的默认提交功能
            rules: {
                loginName: {
                    required: true,
                    remote: {
                        url: "<%=url%>/user/validate",
                        type: "GET",
                        data: {
                            loginName: function () {
                                return $("#loginName").val();
                            }
                        },
                        dataFilter: function (data, type) {
                            if (data == "error")
                                return true;
                            else
                                return false;
                        }
                    }
                }
            },
            messages: {
                loginName: {
                    required: "请输入登录名",
                    remote: "用户名已经被注册"
                }
            },
            submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                $.ajax({
                    url: form.action,
                    type: form.method,
                    data: $(form).serialize(),
                    success: function (data) {
                        // 提交表单
                        if (data == "success") {
                            alert("提交成功！");
                            //$("#editForm")[0].reset();
                            window.parent.location.reload();
                        } else {
                            alert("提交失败！");
                        }
                    }
                });
            },
        });
    });
</script>

</body>
</html>
